include("shared.lua");
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
-- Setting up all the different properties of our melon.
ENT.Delay = 15;
ENT.Healthlol = 200;
ENT.FiringRange = 1300;
ENT.NoMoveRange = 0;
ENT.MinRange = 0;
ENT.DeathRadius = 300;
ENT.DeathMagnitude = 60;
ENT.MaxMelons = 4;
ENT.ActiveMelons = 0;
ENT.MovingForce = 0;
ENT.Move = true;
ENT.Patrol = 0;
ENT.MelonModel = "models/props_trainstation/trainstation_clock001.mdl";

-- Now we tell the base class to set up the melon. Pay attention - the variables must be defined BEFORE calling Setup().
function ENT:Initialize()
	self:Setup();
	if (self.Team == 1) then
	self.Entity:SetColor (125, 0, 0, 255)
	end
	if (self.Team == 2) then
	self.Entity:SetColor (0, 0, 125, 255)
	end
	if (self.Team == 3) then
	self.Entity:SetColor (0, 125, 0, 255)
	end
	if (self.Team == 4) then
	self.Entity:SetColor (125, 125, 0, 255)
	end
	if (self.Team == 5) then
	self.Entity:SetColor (125, 0, 125, 255)
	end
	if (self.Team == 6) then
	self.Entity:SetColor (0, 125, 125, 255)
	end
end


function ENT:Think()
	if self.ActiveMelons < self.MaxMelons && self.TargetVec ~= self.Entity:GetPos()  && self.HoldFire ~= 1 then
	local expl=ents.Create("lap_bfighter");
	expl:GetTable().Team = self.Team;
	expl:GetTable().Grav = self.MelonGrav;
	expl:GetTable().Barracks = self.Entity;
	expl:SetPos(self.Entity:GetPos());
	expl:SetOwner(self.Entity);
	if (self.FollowRange ~= 0) then	
		if (self.Leader == nil) then
		expl:GetTable().Leader = self.Entity;
		else
		expl:GetTable().Leader = self.Leader;
		end
	end
	expl:GetTable().Patrol = self.Patrol;
	expl:GetTable().FollowRange = self.FollowRange;
	expl:GetTable().TargetVec = table.Copy(self.TargetVec);
	expl:Spawn();
	expl:Activate();
	local fx = EffectData();
	fx:SetOrigin(expl:GetPos());
	util.Effect("johnny_build", fx);
	self.ActiveMelons = self.ActiveMelons + 1;
	self.Entity:EmitSound("BaseCombatWeapon.WeaponMaterialize", 100, 100);
	end
	self.Entity:NextThink(CurTime()+self.Delay);
	return true;
end
